import QtQuick 2.6

import "../../Base/UiBase"
import "../../Base/Config"

import Cpp.Type 1.0

Item {
    id: root

    property int subject

    height: (110 + 18 + 18) * Size.ratio

    ImageButton {
        id: newPostButton

        onClicked: {
            if(subject === Subject.Pe)
                newerLoader.show()
            else
            {
                selectorLoader.show()
            }
        }

        sourceSize.width: 110 * Size.ratio
        sourceSize.height: 110 * Size.ratio
        width: sourceSize.width
        height: sourceSize.height
        anchors {
            bottom: root.bottom
            horizontalCenter: root.horizontalCenter
            bottomMargin: 18 * Size.ratio
        }
        z: 4
        source: {
            if(subject === Subject.Paint)
                return pressed ? "../../../resources/evaluation/multi/paint/paizhao02.svg" : "../../../resources/evaluation/multi/paint/paizhao01.svg"
            if(subject === Subject.Pe)
                return pressed ? "../../../resources/evaluation/multi/pe/dengpao02.svg" : "../../../resources/evaluation/multi/pe/dengpao01.svg"
            return pressed ? "../../../resources/evaluation/multi/music/luying02.svg" : "../../../resources/evaluation/multi/music/luying01.svg"
        }
    }

    Loader {
        id:selectorLoader
        property string fileUrl
        parent: mainRoot
        anchors.fill: parent
        function show()
        {
            if(subject === Subject.Paint)
                source = "NewPost/Paint/Select.qml"
            else
                source = "NewPost/Music/Select.qml"
        }

        Connections {
            target: selectorLoader.item
            onVisibleChanged: {
                if(!visible)
                {
                    selectorLoader.fileUrl = selectorLoader.item.fileUrl
                    selectorLoader.source = ""
                }
            }
            onSelected: {
                selectorLoader.fileUrl = selectorLoader.item.fileUrl
                selectorLoader.source = ""
                newerLoader.show()
            }
        }
    }

    Loader {
        id:newerLoader
        parent: mainRoot
        anchors.fill: parent
        function show()
        {
            if(subject === Subject.Paint)
                source = "NewPost/Paint/New.qml"
            else if(subject === Subject.Pe)
                source =  "NewPost/PE/New.qml"
            else
                source = "NewPost/Music/New.qml"
        }

        Connections {
            target: newerLoader.item
            onVisibleChanged: {
                if(!newerLoader.item.visible)
                    newerLoader.source = ""
            }
        }

        Binding {
            target: newerLoader.item
            when: newerLoader.item
            property: "source"
            value:  selectorLoader.fileUrl
        }
    }
}
